package com.shinhye.elephantsafe.utils;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class MD5Utils {

	public static String md5(String text) {
		MessageDigest digest = null;
		try {
			digest = MessageDigest.getInstance("MD5");
		} catch (NoSuchAlgorithmException e) {
			e.printStackTrace();
		}
		byte[] bs = digest.digest(text.getBytes());
		
		StringBuffer sb = new StringBuffer();
		for(byte b : bs) {
			int num = b & 0xff;
			String str = Integer.toHexString(num);
			if(str.length() == 1) {
				sb.append("0");
			}
			sb.append(str);
		}
		
		return sb.toString();
	}
}
